package com.lmc.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lmc.R;
import com.lmc.entity.HeartRate;

import java.util.List;

public class AnalyzeFragmentAdapter extends BaseAdapter {
    Context context;
    List<HeartRate.DataBean.ResultcountBean> count_list;

    public AnalyzeFragmentAdapter(Context context, List<HeartRate.DataBean.ResultcountBean> count_list) {
        this.context = context;
        this.count_list = count_list;
    }

    @Override
    public int getCount() {
        return count_list.size();
    }

    @Override
    public HeartRate.DataBean.ResultcountBean getItem(int position) {
        return count_list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.analyze_list_item, null);
            holder = new ViewHolder();
            holder.text = convertView.findViewById(R.id.text);
            holder.value = convertView.findViewById(R.id.value);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.text.setText(getItem(position).getDiseasestate());
        holder.value.setText(getItem(position).getSum() + "");

        return convertView;
    }

    private class ViewHolder {
        TextView text, value;
    }
}
